import React, { useState } from 'react'
import axios from 'axios';
export default function CheShi() {
  const [loading, setLoading] = useState(false);
  const [qian,setqian] = useState(100)
  const handlePayment = async () => {
    setLoading(true);
    try {
      // 调用后端接口生成支付参数
      const response = await axios.get(`http://localhost:3000/createOrder?qian=${qian}`);
      const { data } = response;

      // 跳转到支付宝支付页面
      window.location.href = data;
    } catch (error) {
      console.error('支付失败:', error);
    } finally {
      setLoading(false);
    }
  };
  return (
    <div>
      <h1>支付宝沙箱支付</h1>
      <button onClick={handlePayment} disabled={loading}>
        {loading ? '支付中...' : '立即支付'}
      </button>
    </div>
  )
}
